# @Time : 2024-09-29 9:39
# @Author : Fioman 
# @Phone : 13149920693
"""
用来做设备检测用,主要是用来检测设备能否启动,如果不是原厂设备,不让其运行
"""
import sys

import win32api
import win32con
import wmi


def get_cpu_list():
    """
    获取本机的cpu的序列号
    :return: 
    """
    wm = wmi.WMI()
    cpu_list = []
    for cpu in wm.Win32_processor():
        cpu_list.append(cpu.ProcessorId.strip())
    return cpu_list


def get_disk_list():
    """
    获取系统当前的硬盘的序列号
    :return:
    """
    wm = wmi.WMI()
    disk_list = []
    for disk in wm.Win32_DiskDrive():
        disk_list.append(disk.SerialNumber.strip())
    return disk_list


def verify_device():
    """
    检查设备是否是可信的列表,可信的设备列表,先列出来
    :return:
    """
    trusted_cpu_list = ["BFEBFBFF000A0655'"]
    trusted_disk_list = ["WD-WX41AC9PE5HR", "184409804273", "'WD-WCC6Y5FRKSDN'"]
    local_cpu = get_cpu_list()[0]
    local_disk = get_disk_list()[0]
    try:
        if local_cpu not in trusted_cpu_list and local_disk not in trusted_disk_list:
            win32api.MessageBox(0, "设备不匹配,只能在厂家电脑上运行该软件,请联系厂家", win32con.MB_ICONWARNING)
            sys.exit(0)
    except Exception as e:
        win32api.MessageBox(0, "设备不匹配,只能在原厂设备上运行,请联系厂家", '错误', win32con.MB_ICONWARNING)
        sys.exit(0)


if __name__ == '__main__':
    print(f"cpu 序列号: {get_cpu_list()}")
    print(f"disk 序列号: {get_disk_list()}")
    verify_device()
